package com.jieyang.oa.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jieyang.oa.dao.EmployeeDao;
import com.jieyang.oa.pojo.Vo.AuditVo;
import com.jieyang.oa.pojo.Vo.EmpInfoVo;
import com.jieyang.oa.pojo.entity.Employee;
import com.jieyang.oa.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author 29276
 * @version 1.0
 * @description: TODO
 * @date 2021/8/15 18:12
 */
@Service
@Transactional
public class EmployeeServiceImpl implements EmployeeService {

    @Autowired
    private EmployeeDao employeeDao;

    @Override
    public List<Employee> selectLeader(Integer emptyPe) {
        return employeeDao.selectLeader(emptyPe);
    }

    @Override
    public Integer insert(Employee employee) {
        return employeeDao.insert(employee);
    }

    @Override
    public PageInfo<Employee> selectByPage(int pageNum, int pageSize, Employee employee) {
        PageHelper.startPage(pageNum, pageSize);

        List<Employee> employees = employeeDao.selectAll(employee);

        PageInfo<Employee> employeePageInfo = new PageInfo<>(employees);
        int ceil = (int) Math.ceil((employeeDao.count(employee)*1.0)/pageSize);
        employeePageInfo.setPages(ceil);
        employeePageInfo.setSize(employeeDao.count(employee));
        return employeePageInfo;
    }

    @Override
    public EmpInfoVo selectByEmpId(String empId) {
        return employeeDao.selectByEmpId(empId);
    }

    @Override
    public Integer update(Employee employee) {
        return employeeDao.update(employee);
    }

    @Override
    public Employee selectEmpByEmpId(String empId) {
        return employeeDao.selectEmpByEmpId(empId);
    }

    @Override
    public Integer delete(String empId) {
        return employeeDao.delete(empId);
    }

    @Override
    public Integer initPwd(String empId) {
        return employeeDao.initPwd(empId);
    }
}
